import request from '@/utils/request'

// ==================== 笔记管理 ====================

// 分页查询笔记
export function getNotePage(params) {
  return request({
    url: '/note/pageNote',
    method: 'get',
    params
  })
}

// 获取笔记详情
export function getNoteDetail(id) {
  return request({
    url: `/note/getNoteById/${id}`,
    method: 'get'
  })
}

// 创建笔记
export function createNote(data) {
  return request({
    url: '/note/addOrUpdateNote',
    method: 'post',
    data
  })
}

// 更新笔记
export function updateNote(data) {
  return request({
    url: '/note/addOrUpdateNote',
    method: 'post',
    data
  })
}

// 删除笔记
export function deleteNote(id) {
  return request({
    url: `/note/deleteNote/${id}`,
    method: 'delete'
  })
}

// 批量删除笔记
export function deleteBatchNote(ids) {
  return request({
    url: '/note/deleteBatch',
    method: 'post',
    data: ids
  })
}

// 分享笔记
export function shareNote(id, shareType, expireTime) {
  return request({
    url: `/note/share/${id}`,
    method: 'post',
    params: { shareType, expireTime }
  })
}

// 取消分享
export function unshareNote(id) {
  return request({
    url: `/note/unshare/${id}`,
    method: 'post'
  })
}

// 收藏笔记
export function favoriteNote(id) {
  return request({
    url: `/note/favorite/${id}`,
    method: 'post'
  })
}

// 取消收藏
export function unfavoriteNote(id) {
  return request({
    url: `/note/unfavorite/${id}`,
    method: 'post'
  })
}

// 搜索笔记
export function searchNotes(keyword, limit = 20) {
  return request({
    url: '/note/search',
    method: 'get',
    params: { keyword, limit }
  })
}

// 获取我的笔记
export function getMyNotes(params) {
  return request({
    url: '/note/my',
    method: 'get',
    params
  })
}

// 获取共享笔记
export function getSharedNotes(params) {
  return request({
    url: '/note/shared',
    method: 'get',
    params
  })
}

// 获取收藏笔记
export function getFavoriteNotes(params) {
  return request({
    url: '/note/favorites',
    method: 'get',
    params
  })
}

// ==================== 笔记分类管理 ====================

// 获取分类列表
export function getNoteCategoryList() {
  return request({
    url: '/note-category/categoryList',
    method: 'get'
  })
}

// 获取分类树
export function getNoteCategoryTree() {
  return request({
    url: '/note-category/tree',
    method: 'get'
  })
}

// 获取分类详情
export function getNoteCategoryDetail(id) {
  return request({
    url: `/note-category/categoryDetail/${id}`,
    method: 'get'
  })
}

// 创建分类
export function createNoteCategory(data) {
  return request({
    url: '/note-category/addOrUpdateCategory',
    method: 'post',
    data
  })
}

// 更新分类
export function updateNoteCategory(data) {
  return request({
    url: '/note-category/addOrUpdateCategory',
    method: 'post',
    data
  })
}

// 删除分类
export function deleteNoteCategory(id) {
  return request({
    url: `/note-category/deleteCategory/${id}`,
    method: 'delete'
  })
}

// ==================== 笔记协作管理 ====================

// 邀请协作者
export function inviteCollaborator(noteId, data) {
  return request({
    url: `/note-collaboration/invite/${noteId}`,
    method: 'post',
    data
  })
}

// 移除协作者
export function removeCollaborator(noteId, userId) {
  return request({
    url: `/note-collaboration/remove/${noteId}/${userId}`,
    method: 'delete'
  })
}

// 更新协作权限
export function updateCollaboratorPermission(noteId, userId, permission) {
  return request({
    url: `/note-collaboration/permission/${noteId}/${userId}`,
    method: 'put',
    params: { permission }
  })
}

// 获取协作者列表
export function getCollaborators(noteId) {
  return request({
    url: `/note-collaboration/collaborators/${noteId}`,
    method: 'get'
  })
}

// 获取协作笔记列表
export function getCollaborativeNotes(params) {
  return request({
    url: '/note-collaboration/notes',
    method: 'get',
    params
  })
}

// ==================== 笔记版本管理 ====================

// 获取版本历史
export function getNoteVersions(noteId, params) {
  return request({
    url: `/note-version/versions/${noteId}`,
    method: 'get',
    params
  })
}

// 获取版本详情
export function getNoteVersionDetail(versionId) {
  return request({
    url: `/note-version/version/${versionId}`,
    method: 'get'
  })
}

// 恢复版本
export function restoreNoteVersion(noteId, versionId) {
  return request({
    url: `/note-version/restore/${noteId}/${versionId}`,
    method: 'post'
  })
}

// 比较版本
export function compareNoteVersions(noteId, version1, version2) {
  return request({
    url: `/note-version/compare/${noteId}`,
    method: 'get',
    params: { version1, version2 }
  })
}
